package com.company.设计模式.单例模式;

/**
 * @author uguoy089
 * @Description:
 * @Date: 2021/5/11 09:10
 *
 * 五种单例模式：
 * 1、懒汉式
 * 2、饿汉式
 * 3、双重检查模式 (DCL)
 * 4、静态内部类
 * 5、枚举类
 */

public class Test {
    public static void main(String[] args) {
        // 懒汉式
        Singleton1 instance1 = Singleton1.getInstance();
        System.out.println(instance1);
        // 饿汉式
        Singleton2 instance2 = Singleton2.getInstance();
        System.out.println(instance2);
        // 双重检查模式 (DCL)
        Singleton3 instance3 = Singleton3.getInstance();
        System.out.println(instance3);
        // 静态内部类
        Singleton4 instance4 = Singleton4.getInstance();
        System.out.println(instance4);
        // 枚举
        Singleton5 instance5 = Singleton5.INSTANCE;
        System.out.println(instance5);

//        Singleton instance = Singleton.INSTANCE;
//        Singleton instance_has_parameter = Singleton.INSTANCE_HAVE_PARAMETER;
//
//        System.out.println("instance = " + instance);
//        System.out.println("instance_has_parameter = " + instance_has_parameter);
    }
}
